package com.wxy.web.security.authorization;

import com.wxy.common.utils.ResponseUtil;
import com.wxy.common.utils.ValidResult;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RestAuthenticationAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
        ValidResult validResult = new ValidResult();
        validResult.fail("", "Error", "权限不足");
        ResponseUtil.write(response, HttpStatus.FORBIDDEN.value(), validResult);
    }

}
